<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Tables</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
MathJax = {
	tex: {
		inlineMath: '$', '$'], ['\\(', '\\)'
	},
	svg: {
		fontCache: 'global'
	}
};
</script>
<script type="text/javascript" id="MathJax-script" async
	src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-svg.js">
</script>

<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Tables' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../extensions.html">Kits</a></li><li><a href="index.html">BasicInformKit</a></li><li><b>Tables</b></li></ul></div>
<p class="purpose">Tables  To read, write, search and allocate rows in the Table data structure.</p>

<ul class="toc"><li><a href="tbls.html#SP1">&#167;1. Format</a></li><li><a href="tbls.html#SP2">&#167;2. Find Column</a></li><li><a href="tbls.html#SP3">&#167;3. Number of Rows</a></li><li><a href="tbls.html#SP4">&#167;4. Blanks</a></li><li><a href="tbls.html#SP5">&#167;5. Masks</a></li><li><a href="tbls.html#SP6">&#167;6. Testing Blankness</a></li><li><a href="tbls.html#SP7">&#167;7. Force Entry Blank</a></li><li><a href="tbls.html#SP8">&#167;8. Force Entry Non-Blank</a></li><li><a href="tbls.html#SP9">&#167;9. Swapping Blank Bits</a></li><li><a href="tbls.html#SP10">&#167;10. Moving Blank Bits Down</a></li><li><a href="tbls.html#SP11">&#167;11. Table Row Corresponding</a></li><li><a href="tbls.html#SP12">&#167;12. Table Look Up Corresponding Row</a></li><li><a href="tbls.html#SP13">&#167;13. Table Look Up Entry</a></li><li><a href="tbls.html#SP14">&#167;14. Blank Rows</a></li><li><a href="tbls.html#SP15">&#167;15. Random Row</a></li><li><a href="tbls.html#SP16">&#167;16. Swap Rows</a></li><li><a href="tbls.html#SP17">&#167;17. Compare Rows</a></li><li><a href="tbls.html#SP19">&#167;19. Move Row Down</a></li><li><a href="tbls.html#SP20">&#167;20. Shuffle</a></li><li><a href="tbls.html#SP21">&#167;21. Next Row</a></li><li><a href="tbls.html#SP22">&#167;22. Move Blanks to Back</a></li><li><a href="tbls.html#SP23">&#167;23. Sort</a></li><li><a href="tbls.html#SP24">&#167;24. Print Table to File</a></li><li><a href="tbls.html#SP25">&#167;25. Read Table from File</a></li><li><a href="tbls.html#SP26">&#167;26. Debugging</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Format.</b>The I7 Table structure is not to be confused with the I6 <span class="extract"><span class="extract-syntax">table</span></span> form of
array: it is essentially a two-dimensional array which has some metadata
at the top of each column.
</p>

<p class="commentary">The run-time representation for a Table is the address <span class="extract"><span class="extract-syntax">T</span></span> of an I6 <span class="extract"><span class="extract-syntax">table</span></span>
array: that is, <span class="extract"><span class="extract-syntax">T--&gt;0</span></span> holds the number of columns (which is at most 99)
and <span class="extract"><span class="extract-syntax">T--&gt;i</span></span> is the address of column number <span class="extract"><span class="extract-syntax">i</span></span>. Columns are therefore
numbered from 1 to <span class="extract"><span class="extract-syntax">T--&gt;0</span></span>, but they are also identified by an ID number of
100 or more, with each different column name having its own ID number.
(This is so that multiple tables can share columns with the same name, and
correlate them: it also means that Inform's type-checking machinery can know
the kind of value of a table entry from the name of the column alone.)
</p>

<p class="commentary">Each column <span class="extract"><span class="extract-syntax">C</span></span> is also a <span class="extract"><span class="extract-syntax">table</span></span> array, with <span class="extract"><span class="extract-syntax">C--&gt;1</span></span> holding the unique
ID number for the column's name, <span class="extract"><span class="extract-syntax">C--&gt;2</span></span> holding the blank entry flags
offset and <span class="extract"><span class="extract-syntax">C--&gt;3</span></span> up to <span class="extract"><span class="extract-syntax">C--&gt;(C--&gt;0)</span></span> holding the entries.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">C--&gt;1</span></span> also contains seven upper bit flags. These are also defined in
"Tables.w" in the Inform source, and the values must agree.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">TB_COLUMN_REAL</span><span class="plain-syntax">        </span><span class="constant-syntax">$8000</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">TB_COLUMN_SIGNED</span><span class="plain-syntax">      </span><span class="constant-syntax">$4000</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">TB_COLUMN_TOPIC</span><span class="plain-syntax">       </span><span class="constant-syntax">$2000</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">TB_COLUMN_DONTSORTME</span><span class="plain-syntax">  </span><span class="constant-syntax">$1000</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">TB_COLUMN_NOBLANKBITS</span><span class="plain-syntax"> </span><span class="constant-syntax">$0800</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">TB_COLUMN_CANEXCHANGE</span><span class="plain-syntax"> </span><span class="constant-syntax">$0400</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">TB_COLUMN_ALLOCATED</span><span class="plain-syntax">   </span><span class="constant-syntax">$0200</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">TB_COLUMN_NUMBER</span><span class="plain-syntax">      </span><span class="constant-syntax">$01ff</span><span class="plain-syntax">; </span><span class="comment-syntax">Mask to remove upper bit flags</span>

<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax"> </span><span class="constant-syntax">2</span><span class="plain-syntax">; </span><span class="comment-syntax">Column header size: two words (ID/flags, blank bits)</span>
</pre>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. Find Column.</b>Columns can be referenced either by their physical column numbers &mdash; from 1
to, potentially, 99 &mdash; or else by unique ID numbers associated with column
names. For instance, if a table has a column called "liquid capacity",
then all references to its "liquid capacity entry" are via the ID number
associated with this column name, which will be \(\geq 100\) and on the other
hand \(\leq\) <span class="extract"><span class="extract-syntax">TB_COLUMN_NUMBER</span></span>. At present, this is only 511, so there can
be at most 411 different column names across all the tables present in the
source text. (It is just about possible to imagine this being a problem on
a very large work, so we will probably one day revise the above to make
use of the larger word-size in Glulx and so raise this limit. But so far
nobody has got even close to it.)
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">f</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_cols</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">no_cols</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">no_cols</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> == ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_NUMBER</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"NonExistentTableColumn"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"No such column in this table."</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"*** Attempt to look up a non-existent column in the table '"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">PrintTableName</span><span class="plain-syntax">) </span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="string-syntax">"'.^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. Number of Rows.</b>The columns in a table can be assumed all to have the same height (i.e.,
number of rows): thus the number of rows in <span class="extract"><span class="extract-syntax">T</span></span> can be calculated by
looking at column 1, thus...
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">first_col</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">first_col</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;1; </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">first_col</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="identifier-syntax">first_col</span><span class="plain-syntax">--&gt;0) - </span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. Blanks.</b>Each table entry is stored in a single word in memory: indeed, column <span class="extract"><span class="extract-syntax">C</span></span>
row <span class="extract"><span class="extract-syntax">R</span></span> is at address <span class="extract"><span class="extract-syntax">(T--&gt;C)--&gt;(R+COL_HSIZE)</span></span>.
</p>

<p class="commentary">But this is not sufficient storage in all cases, because each entry can be
either a value or can be designated "blank". Since, for some columns at
least, the possible values include every number, we find that we have to
store \(2^{16}+1\) possibilities given only a 16-bit memory word. (Well, or
\(2^{32}+1\) with a 32-bit word, depending on the virtual machine.) This
cannot be done.
</p>

<p class="commentary">We therefore need, at least in some cases, an additional bit of storage for
each table entry which indicates whether or not it is blank. If we provided
such a bit for every table entry, that would be a fairly simple system to
implement, but it would also be wasteful of memory, with an overhead of
about 5\% in practice: and memory in the virtual machine is in very short
supply. The reason such a system would be wasteful is that many columns
are known to hold values which are in a narrow range; for instance, a time
of day cannot exceed 1440, and there will never be more than 10,000 rulebooks
or scenes, and so on. For such columns it would be more efficient and indeed
faster to indicate blankness by using an exceptional value in the memory
cell which is such that it cannot be valid for the kind of value stored
in the column. We therefore provide a "blanks bitmap" for only some
columns.
</p>

<p class="commentary">This leads us to define the following dummy value, chosen so that it is
both impossible for most kinds of value &mdash; which is easy to arrange &mdash; and
also unlikely for even those kinds of value where it is legal. For
instance, \(-1\) would be impossible for enumerative kinds of value such as
rulebooks and scenes, but it would be a poor choice for the dummy value
because it occurs pretty often as an integer. Instead we use the constant
<span class="extract"><span class="extract-syntax">IMPROBABLE_VALUE</span></span>, whose value depends on the word size of the virtual
machine, and which is declared in "Definitions.i6t".
</p>

<p class="commentary">An entry is therefore blank if and only if either
</p>

<ul class="items"><li>(a) its column has no blanks bitmap and the stored entry is <span class="extract"><span class="extract-syntax">TABLE_NOVALUE</span></span>, or
</li><li>(b) its column does have a blanks bitmap, the blanks bit for this entry is set,
and the stored entry is also <span class="extract"><span class="extract-syntax">TABLE_NOVALUE</span></span>.
</li></ul>
<p class="commentary">To look up the blanks bitmap is a little slower than to access the stored
entry directly. Most of the time, entries accessed will be non-blank: so it
is efficient to have a system where we can quickly determine this. If we
look at the entry and find that it is not <span class="extract"><span class="extract-syntax">TABLE_NOVALUE</span></span>, then we know
it is not a blank. If we find that it is <span class="extract"><span class="extract-syntax">TABLE_NOVALUE</span></span>, on the other
hand, then quite often the column has no blanks bitmap and again we have
a quick answer: it's blank. Only if the column also has a blanks bitmap do
we need to check that we haven't got a false negative. (The more improbable
<span class="extract"><span class="extract-syntax">TABLE_NOVALUE</span></span> is as a stored value, the rarer it is that we have to
check the blanks bitmap for a non-blank entry.)
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Constant</span><span class="plain-syntax"> </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax"> = </span><span class="identifier-syntax">IMPROBABLE_VALUE</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. Masks.</b>The blanks bitmaps are stored as bytes; we therefore need a quick way to
test or set whether bit number \(i\) of a byte is zero, where \(0\leq i\leq 7\).
I6 provides no very useful operators here, whereas memory lookup is cheap,
so we use two arrays of bitmaps:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">CheckTableEntryIsBlank_LU</span>
<span class="plain-syntax">    -&gt;  </span><span class="constant-syntax">$$00000001</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$00000010</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$00000100</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$00001000</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$00010000</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$00100000</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$01000000</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$10000000</span><span class="plain-syntax">;</span>
<span class="reserved-syntax">Array</span><span class="plain-syntax"> </span><span class="identifier-syntax">CheckTableEntryIsNonBlank_LU</span>
<span class="plain-syntax">    -&gt;  </span><span class="constant-syntax">$$11111110</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$11111101</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$11111011</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$11110111</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$11101111</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$11011111</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$10111111</span>
<span class="plain-syntax">        </span><span class="constant-syntax">$$01111111</span><span class="plain-syntax">;</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. Testing Blankness.</b>The following routine is the one which checks that there is no false negative:
it should be used when we know that the table entry is <span class="extract"><span class="extract-syntax">TABLE_NOVALUE</span></span>
and we need to check the blank bit, if there is one, to make sure the entry
is indeed blank.
</p>

<p class="commentary">The second word in the column table header, <span class="extract"><span class="extract-syntax">C--&gt;2</span></span>, holds the address of the
blanks bitmap: this in turn contains one bit for each row, starting with the
least significant bit of the first byte. If the table contains a number of
rows which isn't a multiple of 8, the spare bits at the end of the last byte
in the blanks bitmap are wasted, but this is an acceptable overhead in
practice.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">at</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">row</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">) ~= </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"*** CTEIB on nonblank value "</span><span class="plain-syntax">, </span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="string-syntax">" "</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="string-syntax">" "</span><span class="plain-syntax">, </span><span class="identifier-syntax">row</span><span class="plain-syntax">, </span><span class="string-syntax">" ***^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_NOBLANKBITS</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">row</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">at</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;2) + (</span><span class="identifier-syntax">row</span><span class="plain-syntax">/8);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">) &amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">row</span><span class="plain-syntax">%8))) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. Force Entry Blank.</b>We blank a table cell by storing <span class="extract"><span class="extract-syntax">TABLE_NOVALUE</span></span> in its entry word and
also setting the relevant bit in the blanks bitmap, if there is one.
</p>

<p class="commentary">We need to be careful if the column holds a kind of value where values are
pointers to blocks of allocated memory, because if so then overwriting such
a value might lead to a memory leak. So in such cases we call <span class="extract"><span class="extract-syntax">DestroyPV</span></span>
to free the memory block. (Note that each memory block is pointed to by one
and only one I7 value at any given time: we are using them as values, not
pointers to values. So if this reference is deleted, it's by definition the
only one.) <span class="extract"><span class="extract-syntax">TABLE_NOVALUE</span></span> is chosen such that it cannot be an address
of a memory block, which is convenient here. (The value 0 means "no memory
block allocated yet".)
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">ForceTableEntryBlank</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">at</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldv</span><span class="plain-syntax"> </span><span class="identifier-syntax">flags</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">flags</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">oldv</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">row</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">flags</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">TB_COLUMN_ALLOCATED</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">oldv</span><span class="plain-syntax"> ~= </span><span class="constant-syntax">0</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DestroyPV</span><span class="plain-syntax">(</span><span class="identifier-syntax">oldv</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">row</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">) = </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">flags</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">TB_COLUMN_NOBLANKBITS</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">row</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">at</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;2) + (</span><span class="identifier-syntax">row</span><span class="plain-syntax">/8);</span>
<span class="plain-syntax">    (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">) = (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">) | (</span><span class="identifier-syntax">CheckTableEntryIsBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">row</span><span class="plain-syntax">%8));</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. Force Entry Non-Blank.</b>To unblank a cell, we need to clear the relevant bit in the bitmap. We then
go on to write a new value in to the entry &mdash; thus overwriting the
<span class="extract"><span class="extract-syntax">TABLE_NOVALUE</span></span> value &mdash; but that isn't done here; the expectation is
that whoever calls this routine is just about to write a new entry anyway.
</p>

<p class="commentary">The exception is again for columns holding a kind of value pointing to a
memory block, where we create a suitable initialised but uninteresting
memory block for the KOV in question, and set the entry to that.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">ForceTableEntryNonBlank</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">at</span><span class="plain-syntax"> </span><span class="identifier-syntax">oldv</span><span class="plain-syntax"> </span><span class="identifier-syntax">flags</span><span class="plain-syntax"> </span><span class="identifier-syntax">tc</span><span class="plain-syntax"> </span><span class="identifier-syntax">kov</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_NOBLANKBITS</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">flags</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">oldv</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">row</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">flags</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">TB_COLUMN_ALLOCATED</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">oldv</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">kov</span><span class="plain-syntax"> = </span><span class="identifier-syntax">UNKNOWN_TY</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">tc</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_NUMBER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">kov</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TC_KOV</span><span class="plain-syntax">(</span><span class="identifier-syntax">tc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">kov</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">UNKNOWN_TY</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">row</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">) = </span><span class="identifier-syntax">CreatePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">kov</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">row</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">at</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;2) + (</span><span class="identifier-syntax">row</span><span class="plain-syntax">/8);</span>
<span class="plain-syntax">    (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">) = (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">) &amp; (</span><span class="identifier-syntax">CheckTableEntryIsNonBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">row</span><span class="plain-syntax">%8));</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. Swapping Blank Bits.</b>When sorting a table, we obviously need to swap rows from time to time; if
any of its columns have blanks bitmaps, then the relevant bits in them
need to be swapped to match, and the following routine performs this operation
for two rows in a given column.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableSwapBlankBits</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">row1</span><span class="plain-syntax"> </span><span class="identifier-syntax">row2</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">at1</span><span class="plain-syntax"> </span><span class="identifier-syntax">at2</span><span class="plain-syntax"> </span><span class="identifier-syntax">bit1</span><span class="plain-syntax"> </span><span class="identifier-syntax">bit2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_NOBLANKBITS</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">row1</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">at1</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;2) + (</span><span class="identifier-syntax">row1</span><span class="plain-syntax">/8);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">row2</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">at2</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;2) + (</span><span class="identifier-syntax">row2</span><span class="plain-syntax">/8);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">bit1</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at1</span><span class="plain-syntax">) &amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">row1</span><span class="plain-syntax">%8)));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">bit2</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at2</span><span class="plain-syntax">) &amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">row2</span><span class="plain-syntax">%8)));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">bit1</span><span class="plain-syntax">) </span><span class="identifier-syntax">bit1</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">bit2</span><span class="plain-syntax">) </span><span class="identifier-syntax">bit2</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">bit1</span><span class="plain-syntax"> == </span><span class="identifier-syntax">bit2</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">bit1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at1</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            = (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at1</span><span class="plain-syntax">) &amp; (</span><span class="identifier-syntax">CheckTableEntryIsNonBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">row1</span><span class="plain-syntax">%8));</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at2</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            = (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at2</span><span class="plain-syntax">) | (</span><span class="identifier-syntax">CheckTableEntryIsBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">row2</span><span class="plain-syntax">%8));</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at1</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            = (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at1</span><span class="plain-syntax">) | (</span><span class="identifier-syntax">CheckTableEntryIsBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">row1</span><span class="plain-syntax">%8));</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at2</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            = (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at2</span><span class="plain-syntax">) &amp; (</span><span class="identifier-syntax">CheckTableEntryIsNonBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">row2</span><span class="plain-syntax">%8));</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. Moving Blank Bits Down.</b>Another common table operation is to compress it by moving all the blank
rows down to the bottom, so that non-blank rows occur in a contiguous block
at the top: this means table sorting can be done without having to refer
continually to the blanks bitmaps. The following operation is useful for
keeping the blanks bitmaps up to date when blank rows are moved down.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableMoveBlankBitsDown</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">row1</span><span class="plain-syntax"> </span><span class="identifier-syntax">row2</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">at</span><span class="plain-syntax"> </span><span class="identifier-syntax">atp1</span><span class="plain-syntax"> </span><span class="identifier-syntax">bit</span><span class="plain-syntax"> </span><span class="identifier-syntax">rx</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_NOBLANKBITS</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">row1</span><span class="plain-syntax">--; </span><span class="identifier-syntax">row2</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">    </span><span class="comment-syntax">Read blank bit for row1:</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">at</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;2) + (</span><span class="identifier-syntax">row1</span><span class="plain-syntax">/8);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">bit</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">) &amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">row1</span><span class="plain-syntax">%8)));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">bit</span><span class="plain-syntax">) </span><span class="identifier-syntax">bit</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="comment-syntax">Loop through, setting each blank bit to the next:</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rx</span><span class="plain-syntax">=</span><span class="identifier-syntax">row1</span><span class="plain-syntax">:</span><span class="identifier-syntax">rx</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">row2</span><span class="plain-syntax">:</span><span class="identifier-syntax">rx</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">atp1</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;2) + ((</span><span class="identifier-syntax">rx</span><span class="plain-syntax">+1)/8);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">at</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;2) + (</span><span class="identifier-syntax">rx</span><span class="plain-syntax">/8);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">atp1</span><span class="plain-syntax">) &amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank_LU</span><span class="plain-syntax">-&gt;((</span><span class="identifier-syntax">rx</span><span class="plain-syntax">+1)%8))) {</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                = (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">) | (</span><span class="identifier-syntax">CheckTableEntryIsBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">rx</span><span class="plain-syntax">%8));</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                = (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">) &amp; (</span><span class="identifier-syntax">CheckTableEntryIsNonBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">rx</span><span class="plain-syntax">%8));</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="comment-syntax">Write bit to blank bit for row2:</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">at</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;2) + (</span><span class="identifier-syntax">row2</span><span class="plain-syntax">/8);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">bit</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            = (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">) | (</span><span class="identifier-syntax">CheckTableEntryIsBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">row2</span><span class="plain-syntax">%8));</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            = (</span><span class="identifier-syntax">TB_Blanks</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">at</span><span class="plain-syntax">) &amp; (</span><span class="identifier-syntax">CheckTableEntryIsNonBlank_LU</span><span class="plain-syntax">-&gt;(</span><span class="identifier-syntax">row2</span><span class="plain-syntax">%8));</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. Table Row Corresponding.</b><span class="extract"><span class="extract-syntax">TableRowCorr(T, C, V)</span></span> returns the first row on which value <span class="extract"><span class="extract-syntax">V</span></span> appears in
column <span class="extract"><span class="extract-syntax">C</span></span> of table <span class="extract"><span class="extract-syntax">T</span></span>, or prints an error if it doesn't.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">ExistsTableRowCorr(T, C, V)</span></span> returns the first row on which <span class="extract"><span class="extract-syntax">V</span></span> appears in
column <span class="extract"><span class="extract-syntax">C</span></span> of table <span class="extract"><span class="extract-syntax">T</span></span>, or 0 if <span class="extract"><span class="extract-syntax">V</span></span> does not occur at all. If the column
is a topic, then we match the entry as a snippet against the value as a
general parsing routine.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableRowCorr</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax"> </span><span class="identifier-syntax">lookup_col</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> </span><span class="identifier-syntax">f</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="reserved-syntax">true</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">lookup_col</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">j</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lookup_col</span><span class="plain-syntax">--&gt;0 - </span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_ALLOCATED</span><span class="plain-syntax">) </span><span class="identifier-syntax">f</span><span class="plain-syntax">=1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">j</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">lookup_col</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">i</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">                (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">i</span><span class="plain-syntax">))) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ComparePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">v</span><span class="plain-syntax">, </span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">j</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">                (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">i</span><span class="plain-syntax">))) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lookup_col</span><span class="plain-syntax">--&gt;(</span><span class="identifier-syntax">i</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">) == </span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">IssueNoCorrespondenceRTP</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">IssueNoCorrespondenceRTP</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"NonExistentTableCorrespondence"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"Could not find a correspondence in this table."</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"*** Tried to look up a non-existent correspondence in the table '"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">PrintTableName</span><span class="plain-syntax">) </span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="string-syntax">"'.^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">ExistsTableRowCorr</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">entry</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> </span><span class="identifier-syntax">f</span><span class="plain-syntax"> </span><span class="identifier-syntax">kov</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">f</span><span class="plain-syntax">=0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_TOPIC</span><span class="plain-syntax">) </span><span class="identifier-syntax">f</span><span class="plain-syntax">=1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_ALLOCATED</span><span class="plain-syntax">) </span><span class="identifier-syntax">f</span><span class="plain-syntax">=2;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">k</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">k</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">i</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">i</span><span class="plain-syntax">))) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax">)(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">/100, </span><span class="identifier-syntax">entry</span><span class="plain-syntax">%100) ~= </span><span class="identifier-syntax">GPR_FAIL</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="constant-syntax">2</span><span class="plain-syntax">: </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ComparePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">v</span><span class="plain-syntax">, </span><span class="identifier-syntax">entry</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">default</span><span class="plain-syntax">: </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">entry</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="comment-syntax">print "Giving up^";</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. Table Look Up Corresponding Row.</b><span class="extract"><span class="extract-syntax">TableLookUpCorr(T, C1, C2, V)</span></span> finds the first row on which value <span class="extract"><span class="extract-syntax">V</span></span>
appears in column <span class="extract"><span class="extract-syntax">C2</span></span>, and returns the corresponding value in <span class="extract"><span class="extract-syntax">C1</span></span>, or
prints an error if the value <span class="extract"><span class="extract-syntax">V</span></span> cannot be found or has no corresponding
value in <span class="extract"><span class="extract-syntax">C1</span></span>.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">ExistsTableLookUpCorr(T, C1, C2, V)</span></span> returns <span class="extract"><span class="extract-syntax">true</span></span> if the operation
<span class="extract"><span class="extract-syntax">TableLookUpCorr(T, C1, C2, V)</span></span> can be done, <span class="extract"><span class="extract-syntax">false</span></span> otherwise.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableLookUpCorr</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col1</span><span class="plain-syntax"> </span><span class="identifier-syntax">col2</span><span class="plain-syntax"> </span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax"> </span><span class="identifier-syntax">write_flag</span><span class="plain-syntax"> </span><span class="identifier-syntax">write_value</span><span class="plain-syntax"> </span><span class="identifier-syntax">cola1</span><span class="plain-syntax"> </span><span class="identifier-syntax">cola2</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> </span><span class="identifier-syntax">f</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col1</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col1</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col1</span><span class="plain-syntax">, </span><span class="reserved-syntax">true</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col2</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col2</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col2</span><span class="plain-syntax">, </span><span class="reserved-syntax">true</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">cola1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">cola2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">j</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cola2</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">f</span><span class="plain-syntax">=0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col2</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_ALLOCATED</span><span class="plain-syntax">) </span><span class="identifier-syntax">f</span><span class="plain-syntax">=1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col2</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_TOPIC</span><span class="plain-syntax">) </span><span class="identifier-syntax">f</span><span class="plain-syntax">=2;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">j</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cola2</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>

<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col2</span><span class="plain-syntax">,</span><span class="identifier-syntax">i</span><span class="plain-syntax">-</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">))) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ComparePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">v</span><span class="plain-syntax">, </span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax">) ~= </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax"> == </span><span class="constant-syntax">2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax">)(</span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax">/100, </span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax">%100) == </span><span class="identifier-syntax">GPR_FAIL</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">v</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">write_flag</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">write_flag</span><span class="plain-syntax"> == </span><span class="constant-syntax">4</span><span class="plain-syntax">) </span><span class="identifier-syntax">ForceTableEntryBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col1</span><span class="plain-syntax">,</span><span class="identifier-syntax">i</span><span class="plain-syntax">-</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">ForceTableEntryNonBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col1</span><span class="plain-syntax">,</span><span class="identifier-syntax">i</span><span class="plain-syntax">-</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">write_flag</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="constant-syntax">1</span><span class="plain-syntax">: </span><span class="identifier-syntax">cola1</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">write_value</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="constant-syntax">2</span><span class="plain-syntax">: </span><span class="identifier-syntax">cola1</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cola1</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> + </span><span class="identifier-syntax">write_value</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="constant-syntax">3</span><span class="plain-syntax">: </span><span class="identifier-syntax">cola1</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cola1</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> - </span><span class="identifier-syntax">write_value</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="constant-syntax">5</span><span class="plain-syntax">: </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">cola1</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cola1</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col1</span><span class="plain-syntax">,</span><span class="identifier-syntax">i</span><span class="plain-syntax">-</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">))) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">IssueNoCorrespondenceRTP</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">ExistsTableLookUpCorr</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col1</span><span class="plain-syntax"> </span><span class="identifier-syntax">col2</span><span class="plain-syntax"> </span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax"> </span><span class="identifier-syntax">cola1</span><span class="plain-syntax"> </span><span class="identifier-syntax">cola2</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> </span><span class="identifier-syntax">f</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col1</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col1</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col1</span><span class="plain-syntax">, </span><span class="reserved-syntax">false</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col2</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col2</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col2</span><span class="plain-syntax">, </span><span class="reserved-syntax">false</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col1</span><span class="plain-syntax">*</span><span class="identifier-syntax">col2</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">cola1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col1</span><span class="plain-syntax">; </span><span class="identifier-syntax">cola2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">j</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cola2</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">f</span><span class="plain-syntax">=0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col2</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_ALLOCATED</span><span class="plain-syntax">) </span><span class="identifier-syntax">f</span><span class="plain-syntax">=1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col2</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_TOPIC</span><span class="plain-syntax">) </span><span class="identifier-syntax">f</span><span class="plain-syntax">=2;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">j</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">cola1</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp;</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col1</span><span class="plain-syntax">,</span><span class="identifier-syntax">i</span><span class="plain-syntax">-</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">))) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ComparePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">cola2</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax">) ~= </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax"> == </span><span class="constant-syntax">2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">cola2</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">)(</span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax">/100, </span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax">%100) == </span><span class="identifier-syntax">GPR_FAIL</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">cola2</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">lookup_value</span><span class="plain-syntax">) </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. Table Look Up Entry.</b><span class="extract"><span class="extract-syntax">TableLookUpEntry(T, C, R)</span></span> returns the value at column <span class="extract"><span class="extract-syntax">C</span></span>, row <span class="extract"><span class="extract-syntax">R</span></span>, printing
an error if that doesn't exist.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">ExistsTableLookUpEntry(T, C, R)</span></span> returns true if a value exists at column
<span class="extract"><span class="extract-syntax">C</span></span>, row <span class="extract"><span class="extract-syntax">R</span></span>, false otherwise.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableLookUpEntry</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">index</span><span class="plain-syntax"> </span><span class="identifier-syntax">write_flag</span><span class="plain-syntax"> </span><span class="identifier-syntax">write_value</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">tab</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"AccessedEntryWithNoRowSelected"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"Attempt to access an entry from a non-existent table."</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="reserved-syntax">true</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">index</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">1</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">index</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"NonExistentTableRow"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"No such row in this table."</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"*** Attempt to look up a non-existent row in the table '"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">PrintTableName</span><span class="plain-syntax">) </span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="string-syntax">"'.^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">index</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">write_flag</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">switch</span><span class="plain-syntax">(</span><span class="identifier-syntax">write_flag</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="constant-syntax">1</span><span class="plain-syntax">:  </span><span class="identifier-syntax">ForceTableEntryNonBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">index</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">index</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">) = </span><span class="identifier-syntax">write_value</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="constant-syntax">2</span><span class="plain-syntax">:  </span><span class="identifier-syntax">ForceTableEntryNonBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">index</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">index</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">) =</span>
<span class="plain-syntax">                    ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">index</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">)) + </span><span class="identifier-syntax">write_value</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="constant-syntax">3</span><span class="plain-syntax">:  </span><span class="identifier-syntax">ForceTableEntryNonBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">index</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">index</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">) =</span>
<span class="plain-syntax">                    ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">index</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">)) - </span><span class="identifier-syntax">write_value</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="constant-syntax">4</span><span class="plain-syntax">:  </span><span class="identifier-syntax">ForceTableEntryBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">index</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="constant-syntax">5</span><span class="plain-syntax">:  </span><span class="identifier-syntax">ForceTableEntryNonBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">index</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">return</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">index</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">index</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">index</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"NonExistentTableEntry"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"No such entry in this table."</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"** Tried to look up a non-existent entry at column "</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">", row "</span><span class="plain-syntax">, </span><span class="identifier-syntax">index</span><span class="plain-syntax">, </span><span class="string-syntax">" of the table '"</span><span class="plain-syntax">, (</span><span class="identifier-syntax">PrintTableName</span><span class="plain-syntax">) </span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="string-syntax">"'.^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">ExistsTableLookUpEntry</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">index</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">index</span><span class="plain-syntax">&lt;1) || (</span><span class="identifier-syntax">index</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">))) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">index</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">index</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. Blank Rows.</b><span class="extract"><span class="extract-syntax">TableRowIsBlank(T, R)</span></span> returns true if row <span class="extract"><span class="extract-syntax">R</span></span> of table <span class="extract"><span class="extract-syntax">T</span></span> is blank. (<span class="extract"><span class="extract-syntax">R</span></span>
must be a legal row number.)
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">TableBlankOutRow(T, R)</span></span> fills row <span class="extract"><span class="extract-syntax">R</span></span> of table <span class="extract"><span class="extract-syntax">T</span></span> with blanks. (<span class="extract"><span class="extract-syntax">R</span></span> must be
a legal row number.)
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">TableBlankRows(T)</span></span> returns the number of blank rows in <span class="extract"><span class="extract-syntax">T</span></span>.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">TableFilledRows(T)</span></span> returns the number of non-blank rows in <span class="extract"><span class="extract-syntax">T</span></span>.
</p>

<p class="commentary"><span class="extract"><span class="extract-syntax">TableBlankRow(T)</span></span> finds the first blank row in <span class="extract"><span class="extract-syntax">T</span></span>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableRowIsBlank</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">k</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">k</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;0:</span><span class="identifier-syntax">k</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">k</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">j</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">)) ~= </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">k</span><span class="plain-syntax">, </span><span class="identifier-syntax">j</span><span class="plain-syntax">) == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">IssueNoTableToBlankRTP</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"BlankedOutRowFromNonExistentTable"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"No table to blank out a row from."</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">TableBlankOutRow</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">==0) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">IssueNoTableToBlankRTP</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">k</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">k</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;0:</span><span class="identifier-syntax">k</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ForceTableEntryBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">k</span><span class="plain-syntax">, </span><span class="identifier-syntax">row</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">TableBlankOutColumn</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">==0) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">IssueNoTableToBlankRTP</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">k</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">k</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">n</span><span class="plain-syntax">:</span><span class="identifier-syntax">k</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ForceTableEntryBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="identifier-syntax">k</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">TableBlankOutAll</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">n</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">==0) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">IssueNoTableToBlankRTP</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">n</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">k</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">k</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">n</span><span class="plain-syntax">:</span><span class="identifier-syntax">k</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TableBlankOutRow</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">k</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">TableBlankRows</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">); </span><span class="comment-syntax">rint i, " rows^";</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">j</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">i</span><span class="plain-syntax">:</span><span class="identifier-syntax">j</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">TableRowIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">j</span><span class="plain-syntax">)) </span><span class="identifier-syntax">c</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">    </span><span class="comment-syntax">rint c, " blank^";</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">TableFilledRows</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">) - </span><span class="identifier-syntax">TableBlankRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">TableBlankRow</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">j</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">i</span><span class="plain-syntax">:</span><span class="identifier-syntax">j</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">TableRowIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">j</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"BlankRowsRanOut"</span><span class="plain-syntax">, </span><span class="string-syntax">"Out of blank rows."</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"*** Tried to choose a blank row in table '"</span><span class="plain-syntax">, (</span><span class="identifier-syntax">PrintTableName</span><span class="plain-syntax">) </span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="string-syntax">"'.^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. Random Row.</b><span class="extract"><span class="extract-syntax">TableRandomRow(T)</span></span> chooses a random non-blank row in <span class="extract"><span class="extract-syntax">T</span></span>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableRandomRow</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">j</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableFilledRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">==0) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"ChoseRandomRowFromBlankTable"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            </span><span class="string-syntax">"This table is empty."</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"*** Tried to choose a random row in an entirely blank table: table '"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    (</span><span class="identifier-syntax">PrintTableName</span><span class="plain-syntax">) </span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="string-syntax">"'.^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">&gt;1) </span><span class="identifier-syntax">j</span><span class="plain-syntax"> = </span><span class="reserved-syntax">random</span><span class="plain-syntax">(</span><span class="identifier-syntax">j</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">k</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">k</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">i</span><span class="plain-syntax">:</span><span class="identifier-syntax">k</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">TableRowIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">k</span><span class="plain-syntax">) == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) </span><span class="identifier-syntax">j</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">j</span><span class="plain-syntax">==0) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. Swap Rows.</b><span class="extract"><span class="extract-syntax">TableSwapRows(T, R1, R2)</span></span> exchanges rows <span class="extract"><span class="extract-syntax">R1</span></span> and <span class="extract"><span class="extract-syntax">R2</span></span>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableSwapRows</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax"> </span><span class="identifier-syntax">l</span><span class="plain-syntax"> </span><span class="identifier-syntax">v1</span><span class="plain-syntax"> </span><span class="identifier-syntax">v2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">==</span><span class="identifier-syntax">j</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">l</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">k</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">k</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">l</span><span class="plain-syntax">:</span><span class="identifier-syntax">k</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">v1</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">k</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">i</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">v2</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">k</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">j</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">k</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">i</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">) = </span><span class="identifier-syntax">v2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">k</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">j</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">) = </span><span class="identifier-syntax">v1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v1</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">v2</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">))</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">TableSwapBlankBits</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="identifier-syntax">j</span><span class="plain-syntax">, </span><span class="identifier-syntax">k</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP17" class="paragraph-anchor"></a><b>&#167;17. Compare Rows.</b><span class="extract"><span class="extract-syntax">TableCompareRows(T, C, R1, R2, D)</span></span> returns:
</p>

<ul class="items"><li>(a) \(+1\) if the entry at row R1 of column C is \(&gt;\) the entry at row R2,
</li><li>(b) 0 if they are equal, and
</li><li>(c) \(-1\) if entry at R1 \(&lt;\) entry at R2.
</li></ul>
<p class="commentary">When \(D = +1\), a blank value is greater than all other values, so that in
an ascending sort the blanks come last; when \(D = -1\), a blank value is
less than all others, so that once again blanks are last. Finally, a wholly
blank row is always placed after a row in which the entry in C is blank but
where other entries are not.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableCompareRows</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">row1</span><span class="plain-syntax"> </span><span class="identifier-syntax">row2</span><span class="plain-syntax"> </span><span class="identifier-syntax">dir</span><span class="plain-syntax"> </span><span class="identifier-syntax">val1</span><span class="plain-syntax"> </span><span class="identifier-syntax">val2</span><span class="plain-syntax"> </span><span class="identifier-syntax">bl1</span><span class="plain-syntax"> </span><span class="identifier-syntax">bl2</span><span class="plain-syntax"> </span><span class="identifier-syntax">f</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="reserved-syntax">false</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">val1</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">row1</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">val2</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">row2</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val1</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">bl1</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">row1</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val2</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">bl2</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">row2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">val1</span><span class="plain-syntax"> == </span><span class="identifier-syntax">val2</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">bl1</span><span class="plain-syntax"> == </span><span class="identifier-syntax">bl2</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val1</span><span class="plain-syntax"> ~= </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">bl1</span><span class="plain-syntax"> == </span><span class="reserved-syntax">false</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="comment-syntax">The two entries are both blank:</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">TableRowIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">row1</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">TableRowIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">row2</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1*</span><span class="identifier-syntax">dir</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">TableRowIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">row2</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">dir</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">bl1</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">dir</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">bl2</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1*</span><span class="identifier-syntax">dir</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">f</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">TB_COLUMN_ALLOCATED</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ComparePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">val2</span><span class="plain-syntax">, </span><span class="identifier-syntax">val1</span><span class="plain-syntax">) &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">TB_COLUMN_REAL</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">REAL_NUMBER_TY_Compare</span><span class="plain-syntax">(</span><span class="identifier-syntax">val1</span><span class="plain-syntax">, </span><span class="identifier-syntax">val2</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">TB_COLUMN_SIGNED</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">val1</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">val2</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">UnsignedCompare</span><span class="plain-syntax">(</span><span class="identifier-syntax">val1</span><span class="plain-syntax">, </span><span class="identifier-syntax">val2</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> -1;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP18" class="paragraph-anchor"></a><b>&#167;18. </b><span class="extract"><span class="extract-syntax">TableCompareRowsCustomCF(T, C, R1, R2, D)</span></span> is similar, but calls a custom
comparison function, and so ignores the <span class="extract"><span class="extract-syntax">C</span></span> parameter. The <span class="extract"><span class="extract-syntax">D</span></span> parameter is
also ignored at present.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">Global</span><span class="plain-syntax"> </span><span class="identifier-syntax">Table_Sort_cf</span><span class="plain-syntax">;</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">TableCompareRowsCustomCF</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">row1</span><span class="plain-syntax"> </span><span class="identifier-syntax">row2</span><span class="plain-syntax"> </span><span class="identifier-syntax">dir</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Table_Sort_cf</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">row1</span><span class="plain-syntax">, </span><span class="identifier-syntax">row2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP19" class="paragraph-anchor"></a><b>&#167;19. Move Row Down.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableMoveRowDown</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">r1</span><span class="plain-syntax"> </span><span class="identifier-syntax">r2</span><span class="plain-syntax"> </span><span class="identifier-syntax">rx</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax"> </span><span class="identifier-syntax">l</span><span class="plain-syntax"> </span><span class="identifier-syntax">m</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> </span><span class="identifier-syntax">f</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">r1</span><span class="plain-syntax">==</span><span class="identifier-syntax">r2</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">l</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">k</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">k</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">l</span><span class="plain-syntax">:</span><span class="identifier-syntax">k</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">f</span><span class="plain-syntax"> = </span><span class="reserved-syntax">false</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">m</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">k</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">r1</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">m</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">f</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">rx</span><span class="plain-syntax">=</span><span class="identifier-syntax">r1</span><span class="plain-syntax">:</span><span class="identifier-syntax">rx</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">r2</span><span class="plain-syntax">:</span><span class="identifier-syntax">rx</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">k</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">rx</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">+1);</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">k</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">rx</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">) = </span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) </span><span class="identifier-syntax">f</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">k</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">r2</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">) = </span><span class="identifier-syntax">m</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax">) </span><span class="identifier-syntax">TableMoveBlankBitsDown</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">r1</span><span class="plain-syntax">, </span><span class="identifier-syntax">r2</span><span class="plain-syntax">, </span><span class="identifier-syntax">k</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP20" class="paragraph-anchor"></a><b>&#167;20. Shuffle.</b><span class="extract"><span class="extract-syntax">TableShuffle(T)</span></span> sorts <span class="extract"><span class="extract-syntax">T</span></span> into random row order.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableShuffle</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="reserved-syntax">to</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TableMoveBlanksToBack</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">to</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableFilledRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=2:</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="reserved-syntax">to</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">TableSwapRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="reserved-syntax">random</span><span class="plain-syntax">(</span><span class="identifier-syntax">i</span><span class="plain-syntax">));</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP21" class="paragraph-anchor"></a><b>&#167;21. Next Row.</b><span class="extract"><span class="extract-syntax">TableNextRow(T, C, R, D)</span></span> is used when scanning through a table in order
of the values in column <span class="extract"><span class="extract-syntax">C</span></span>: ascending order if <span class="extract"><span class="extract-syntax">D = 1</span></span>, descending if <span class="extract"><span class="extract-syntax">D =
</span></span>-1<span class="extract"><span class="extract-syntax">. The current position is row </span></span>R<span class="extract"><span class="extract-syntax"> of column </span></span>C<span class="extract"><span class="extract-syntax">, or </span></span>R = 0<span class="extract"><span class="extract-syntax"> if we have
</span></span>not yet found the first row. The return value is the row number for the
next value, or 0 if we are already at the final value. Note that if there
are several equal values in the column, they will be run through in turn,
in order of their physical row numbers - ascending if <span class="extract"><span class="extract-syntax">D = 1</span></span>, descending
if <span class="extract"><span class="extract-syntax">D = -1</span></span>, so that using the routine with <span class="extract"><span class="extract-syntax">D = -1</span></span> always produces the
exact reverse ordering from using it with <span class="extract"><span class="extract-syntax">D = 1</span></span> and the same parameters.
Rows with blank entries in <span class="extract"><span class="extract-syntax">C</span></span> are skipped.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">R</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableNextRow</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">,</span><span class="identifier-syntax">C</span><span class="plain-syntax">,0,</span><span class="identifier-syntax">D</span><span class="plain-syntax">): </span><span class="identifier-syntax">R</span><span class="plain-syntax"> : </span><span class="identifier-syntax">R</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableNextRow</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">,</span><span class="identifier-syntax">C</span><span class="plain-syntax">,</span><span class="identifier-syntax">R</span><span class="plain-syntax">,</span><span class="identifier-syntax">D</span><span class="plain-syntax">)) ...</span>
</pre>
<p class="commentary">will perform a loop of valid row numbers in order of column <span class="extract"><span class="extract-syntax">C</span></span>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableNextRow</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax"> </span><span class="identifier-syntax">dir</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> </span><span class="identifier-syntax">dv</span><span class="plain-syntax"> </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax"> </span><span class="identifier-syntax">min_at</span><span class="plain-syntax"> </span><span class="identifier-syntax">signed_arithmetic</span><span class="plain-syntax"> </span><span class="identifier-syntax">f</span><span class="plain-syntax"> </span><span class="identifier-syntax">blk</span><span class="plain-syntax"> </span><span class="identifier-syntax">z</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="reserved-syntax">false</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">f</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">TB_COLUMN_ALLOCATED</span><span class="plain-syntax">) </span><span class="identifier-syntax">blk</span><span class="plain-syntax"> = </span><span class="reserved-syntax">true</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">signed_arithmetic</span><span class="plain-syntax"> = </span><span class="identifier-syntax">f</span><span class="plain-syntax"> &amp; </span><span class="identifier-syntax">TB_COLUMN_SIGNED</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">Iftrue</span><span class="plain-syntax"> </span><span class="identifier-syntax">WORDSIZE</span><span class="plain-syntax"> == </span><span class="constant-syntax">2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">signed_arithmetic</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">dir</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="constant-syntax">$8000</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="constant-syntax">$7fff</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">dir</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="constant-syntax">$ffff</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">row</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">signed_arithmetic</span><span class="plain-syntax">) </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax"> = </span><span class="constant-syntax">$7fff</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax"> = </span><span class="constant-syntax">$ffff</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">ifnot</span><span class="plain-syntax">; </span><span class="comment-syntax">WORDSIZE == 4</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">signed_arithmetic</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">dir</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="constant-syntax">$80000000</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="constant-syntax">$7fffffff</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">dir</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="constant-syntax">$ffffffff</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">row</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">signed_arithmetic</span><span class="plain-syntax">) </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax"> = </span><span class="constant-syntax">$7fffffff</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax"> = </span><span class="constant-syntax">$ffffffff</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    #</span><span class="identifier-syntax">endif</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">k</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">dir</span><span class="plain-syntax"> == </span><span class="constant-syntax">1</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">k</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">i</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">i</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">blk</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">dv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">z</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">z</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ComparePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">v</span><span class="plain-syntax">, </span><span class="identifier-syntax">val</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">f</span><span class="plain-syntax"> = (((</span><span class="identifier-syntax">z</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) || ((</span><span class="identifier-syntax">z</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">i</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">row</span><span class="plain-syntax">))) &amp;&amp;</span>
<span class="plain-syntax">                    ((</span><span class="identifier-syntax">min_at</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">ComparePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">v</span><span class="plain-syntax">, </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax">) &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)));</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">dv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">dir</span><span class="plain-syntax">*</span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">signed_arithmetic</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">f</span><span class="plain-syntax"> = (((</span><span class="identifier-syntax">dv</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">dir</span><span class="plain-syntax">*</span><span class="identifier-syntax">val</span><span class="plain-syntax">) || ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">val</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">i</span><span class="plain-syntax">&gt;</span><span class="identifier-syntax">row</span><span class="plain-syntax">))) &amp;&amp;</span>
<span class="plain-syntax">                      (</span><span class="identifier-syntax">dv</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">f</span><span class="plain-syntax"> = (((</span><span class="identifier-syntax">UnsignedCompare</span><span class="plain-syntax">(</span><span class="identifier-syntax">dv</span><span class="plain-syntax">, </span><span class="identifier-syntax">dir</span><span class="plain-syntax">*</span><span class="identifier-syntax">val</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) || ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">val</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">i</span><span class="plain-syntax">&gt;</span><span class="identifier-syntax">row</span><span class="plain-syntax">))) &amp;&amp;</span>
<span class="plain-syntax">                      (</span><span class="identifier-syntax">UnsignedCompare</span><span class="plain-syntax">(</span><span class="identifier-syntax">dv</span><span class="plain-syntax">, </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax">) &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax">) { </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">dv</span><span class="plain-syntax">; </span><span class="identifier-syntax">min_at</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=</span><span class="identifier-syntax">k</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">&gt;=1:</span><span class="identifier-syntax">i</span><span class="plain-syntax">--) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">i</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">i</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">continue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">blk</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">dv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">z</span><span class="plain-syntax"> = -1; </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="identifier-syntax">z</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ComparePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">v</span><span class="plain-syntax">, </span><span class="identifier-syntax">val</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">f</span><span class="plain-syntax"> = (((</span><span class="identifier-syntax">z</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) || ((</span><span class="identifier-syntax">z</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">i</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">row</span><span class="plain-syntax">))) &amp;&amp;</span>
<span class="plain-syntax">                    ((</span><span class="identifier-syntax">min_at</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">ComparePV</span><span class="plain-syntax">(</span><span class="identifier-syntax">v</span><span class="plain-syntax">, </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">)));</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">dv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">dir</span><span class="plain-syntax">*</span><span class="identifier-syntax">v</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">signed_arithmetic</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">f</span><span class="plain-syntax"> = (((</span><span class="identifier-syntax">dv</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">dir</span><span class="plain-syntax">*</span><span class="identifier-syntax">val</span><span class="plain-syntax">) || ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">val</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">row</span><span class="plain-syntax">))) &amp;&amp;</span>
<span class="plain-syntax">                      (</span><span class="identifier-syntax">dv</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">f</span><span class="plain-syntax"> = (((</span><span class="identifier-syntax">UnsignedCompare</span><span class="plain-syntax">(</span><span class="identifier-syntax">dv</span><span class="plain-syntax">, </span><span class="identifier-syntax">dir</span><span class="plain-syntax">*</span><span class="identifier-syntax">val</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) || ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">val</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">row</span><span class="plain-syntax">))) &amp;&amp;</span>
<span class="plain-syntax">                      (</span><span class="identifier-syntax">UnsignedCompare</span><span class="plain-syntax">(</span><span class="identifier-syntax">dv</span><span class="plain-syntax">, </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax">) &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">f</span><span class="plain-syntax">) { </span><span class="identifier-syntax">min_dv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">dv</span><span class="plain-syntax">; </span><span class="identifier-syntax">min_at</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">min_at</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP22" class="paragraph-anchor"></a><b>&#167;22. Move Blanks to Back.</b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableMoveBlanksToBack</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">fromrow</span><span class="plain-syntax"> </span><span class="identifier-syntax">torow</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">fbl</span><span class="plain-syntax"> </span><span class="identifier-syntax">lnbl</span><span class="plain-syntax"> </span><span class="identifier-syntax">blc</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">torow</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">fromrow</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">fbl</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">; </span><span class="identifier-syntax">lnbl</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=</span><span class="identifier-syntax">fromrow</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">torow</span><span class="plain-syntax">: </span><span class="identifier-syntax">i</span><span class="plain-syntax">++)</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">TableRowIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fbl</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) </span><span class="identifier-syntax">fbl</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">blc</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">lnbl</span><span class="plain-syntax"> = </span><span class="identifier-syntax">i</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">fbl</span><span class="plain-syntax">&gt;0) &amp;&amp; (</span><span class="identifier-syntax">lnbl</span><span class="plain-syntax">&gt;0) &amp;&amp; (</span><span class="identifier-syntax">fbl</span><span class="plain-syntax"> &lt; </span><span class="identifier-syntax">lnbl</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TableMoveRowDown</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">fbl</span><span class="plain-syntax">, </span><span class="identifier-syntax">lnbl</span><span class="plain-syntax">); </span><span class="comment-syntax">Move first blank just past last nonblank</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TableMoveBlanksToBack</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">fbl</span><span class="plain-syntax">, </span><span class="identifier-syntax">lnbl</span><span class="plain-syntax">-1);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">torow</span><span class="plain-syntax">-</span><span class="identifier-syntax">blc</span><span class="plain-syntax">; </span><span class="comment-syntax">Final non-blank row</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP23" class="paragraph-anchor"></a><b>&#167;23. Sort.</b>This is really only a front-end: it calls the sorting code at "Sort.i6t".
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableSort</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">dir</span><span class="plain-syntax"> </span><span class="identifier-syntax">algorithm</span><span class="plain-syntax"> </span><span class="identifier-syntax">cf</span><span class="plain-syntax">  </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;0:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">j</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">; </span><span class="comment-syntax">Address of column table</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">j</span><span class="plain-syntax">--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_DONTSORTME</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"SortedTableWithFixedOrdering"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="string-syntax">"Tried to sort a table whose ordering is fixed."</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"*** Tried to sort a table whose ordering must remain fixed: table '"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                    (</span><span class="identifier-syntax">PrintTableName</span><span class="plain-syntax">) </span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="string-syntax">"'.^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">cf</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">Table_Sort_cf</span><span class="plain-syntax"> = </span><span class="identifier-syntax">cf</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">SetSortDomain</span><span class="plain-syntax">(</span><span class="identifier-syntax">TableSwapRows</span><span class="plain-syntax">, </span><span class="identifier-syntax">TableCompareRowsCustomCF</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="reserved-syntax">false</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">SetSortDomain</span><span class="plain-syntax">(</span><span class="identifier-syntax">TableSwapRows</span><span class="plain-syntax">, </span><span class="identifier-syntax">TableCompareRows</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">k</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">k</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableMoveBlanksToBack</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="identifier-syntax">k</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">SortArray</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="identifier-syntax">dir</span><span class="plain-syntax">, </span><span class="identifier-syntax">k</span><span class="plain-syntax">, </span><span class="identifier-syntax">algorithm</span><span class="plain-syntax">);</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP24" class="paragraph-anchor"></a><b>&#167;24. Print Table to File.</b>This is how we serialise a table to an external file, though the writing
is done by printing characters in the standard way; it's just that the output
stream will be an external file rather than the screen when this routine
is called.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TablePrint</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> </span><span class="identifier-syntax">tc</span><span class="plain-syntax"> </span><span class="identifier-syntax">kov</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;0:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">j</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">i</span><span class="plain-syntax">; </span><span class="comment-syntax">Address of column table</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">j</span><span class="plain-syntax">--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_CANEXCHANGE</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">k</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">k</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableMoveBlanksToBack</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="identifier-syntax">k</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"! "</span><span class="plain-syntax">, (</span><span class="identifier-syntax">PrintTableName</span><span class="plain-syntax">) </span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="string-syntax">" ("</span><span class="plain-syntax">, </span><span class="identifier-syntax">k</span><span class="plain-syntax">, </span><span class="string-syntax">")^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">row</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">k</span><span class="plain-syntax">:</span><span class="identifier-syntax">row</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">col</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;0:</span><span class="identifier-syntax">col</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">tc</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_NUMBER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">kov</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindWeakID</span><span class="plain-syntax">(</span><span class="identifier-syntax">TC_KOV</span><span class="plain-syntax">(</span><span class="identifier-syntax">tc</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">kov</span><span class="plain-syntax"> == </span><span class="identifier-syntax">UNKNOWN_TY</span><span class="plain-syntax">) </span><span class="identifier-syntax">kov</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NUMBER_TY</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">row</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">row</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"--"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">SerialiseKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">kov</span><span class="plain-syntax">, </span><span class="identifier-syntax">v</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rfalse</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP25" class="paragraph-anchor"></a><b>&#167;25. Read Table from File.</b>And this is how we unserialise again. It makes sense only on Glulx.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableRead</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">auxf</span><span class="plain-syntax"> </span><span class="identifier-syntax">row</span><span class="plain-syntax"> </span><span class="identifier-syntax">maxrow</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> </span><span class="identifier-syntax">sgn</span><span class="plain-syntax"> </span><span class="identifier-syntax">dg</span><span class="plain-syntax"> </span><span class="identifier-syntax">j</span><span class="plain-syntax"> </span><span class="identifier-syntax">tc</span><span class="plain-syntax"> </span><span class="identifier-syntax">kov</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">col</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;0:</span><span class="identifier-syntax">col</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">j</span><span class="plain-syntax"> = </span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">; </span><span class="comment-syntax">Address of column table</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">j</span><span class="plain-syntax">--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_CANEXCHANGE</span><span class="plain-syntax">) == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">IssueSavedUnstableTable</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">maxrow</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">row</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">maxrow</span><span class="plain-syntax">: </span><span class="identifier-syntax">row</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TableBlankOutRow</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">row</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">row</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">row</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">maxrow</span><span class="plain-syntax">: </span><span class="identifier-syntax">row</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FileIO_GetC</span><span class="plain-syntax">(</span><span class="identifier-syntax">auxf</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> == </span><span class="character-syntax">'!'</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> ~= -1 </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="constant-syntax">10</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="constant-syntax">13</span><span class="plain-syntax">) </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FileIO_GetC</span><span class="plain-syntax">(</span><span class="identifier-syntax">auxf</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> == </span><span class="constant-syntax">10</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="constant-syntax">13</span><span class="plain-syntax">) </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FileIO_GetC</span><span class="plain-syntax">(</span><span class="identifier-syntax">auxf</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">col</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;0: </span><span class="identifier-syntax">col</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> == -1) { </span><span class="identifier-syntax">row</span><span class="plain-syntax">++; </span><span class="reserved-syntax">jump</span><span class="plain-syntax"> </span><span class="identifier-syntax">NoMore</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> == </span><span class="constant-syntax">10</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="constant-syntax">13</span><span class="plain-syntax">) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">tc</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_NUMBER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">kov</span><span class="plain-syntax"> = </span><span class="identifier-syntax">KindWeakID</span><span class="plain-syntax">(</span><span class="identifier-syntax">TC_KOV</span><span class="plain-syntax">(</span><span class="identifier-syntax">tc</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">kov</span><span class="plain-syntax"> == </span><span class="identifier-syntax">UNKNOWN_TY</span><span class="plain-syntax">) </span><span class="identifier-syntax">kov</span><span class="plain-syntax"> = </span><span class="identifier-syntax">NUMBER_TY</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">sgn</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> == </span><span class="character-syntax">'-'</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FileIO_GetC</span><span class="plain-syntax">(</span><span class="identifier-syntax">auxf</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> == -1) </span><span class="reserved-syntax">jump</span><span class="plain-syntax"> </span><span class="identifier-syntax">NotTable</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> == </span><span class="character-syntax">'-'</span><span class="plain-syntax">) { </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FileIO_GetC</span><span class="plain-syntax">(</span><span class="identifier-syntax">auxf</span><span class="plain-syntax">); </span><span class="reserved-syntax">jump</span><span class="plain-syntax"> </span><span class="identifier-syntax">EntryDone</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">sgn</span><span class="plain-syntax"> = -1;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_ALLOCATED</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">ForceTableEntryNonBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="identifier-syntax">row</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">UnserialiseKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">kov</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, -1);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">v</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_ALLOCATED</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">UnserialiseKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">kov</span><span class="plain-syntax">, </span><span class="identifier-syntax">TableLookUpEntry</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="identifier-syntax">row</span><span class="plain-syntax">), </span><span class="identifier-syntax">auxf</span><span class="plain-syntax">, </span><span class="identifier-syntax">ch</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">UnserialiseKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">kov</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="identifier-syntax">auxf</span><span class="plain-syntax">, </span><span class="identifier-syntax">ch</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> = </span><span class="constant-syntax">32</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">dg</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> - </span><span class="character-syntax">'0'</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">dg</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">dg</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">9</span><span class="plain-syntax">)) </span><span class="reserved-syntax">jump</span><span class="plain-syntax"> </span><span class="identifier-syntax">NotTable</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">dg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (::) {</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FileIO_GetC</span><span class="plain-syntax">(</span><span class="identifier-syntax">auxf</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">dg</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> - </span><span class="character-syntax">'0'</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">dg</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">dg</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">9</span><span class="plain-syntax">)) </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="constant-syntax">10</span><span class="plain-syntax">*</span><span class="identifier-syntax">v</span><span class="plain-syntax"> + </span><span class="identifier-syntax">dg</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = </span><span class="identifier-syntax">v</span><span class="plain-syntax">*</span><span class="identifier-syntax">sgn</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_ALLOCATED</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">TableLookUpEntry</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="identifier-syntax">row</span><span class="plain-syntax">, </span><span class="reserved-syntax">true</span><span class="plain-syntax">, </span><span class="identifier-syntax">v</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            .</span><span class="identifier-syntax">EntryDone</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> == </span><span class="constant-syntax">9</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="constant-syntax">32</span><span class="plain-syntax">) </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FileIO_GetC</span><span class="plain-syntax">(</span><span class="identifier-syntax">auxf</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> ~= -1 </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="constant-syntax">10</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="constant-syntax">13</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> ~= </span><span class="character-syntax">'-'</span><span class="plain-syntax">) &amp;&amp; (((</span><span class="identifier-syntax">ch</span><span class="plain-syntax">-</span><span class="character-syntax">'0'</span><span class="plain-syntax">)&lt;0) || ((</span><span class="identifier-syntax">ch</span><span class="plain-syntax">-</span><span class="character-syntax">'0'</span><span class="plain-syntax">)&gt;9))) </span><span class="reserved-syntax">jump</span><span class="plain-syntax"> </span><span class="identifier-syntax">NotTable</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> ~= </span><span class="constant-syntax">9</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="constant-syntax">32</span><span class="plain-syntax">) </span><span class="reserved-syntax">jump</span><span class="plain-syntax"> </span><span class="identifier-syntax">WontFit</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FileIO_GetC</span><span class="plain-syntax">(</span><span class="identifier-syntax">auxf</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    .</span><span class="identifier-syntax">NoMore</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> == </span><span class="constant-syntax">9</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="constant-syntax">32</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="constant-syntax">10</span><span class="plain-syntax"> </span><span class="reserved-syntax">or</span><span class="plain-syntax"> </span><span class="constant-syntax">13</span><span class="plain-syntax">) </span><span class="identifier-syntax">ch</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FileIO_GetC</span><span class="plain-syntax">(</span><span class="identifier-syntax">auxf</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ch</span><span class="plain-syntax"> == -1) </span><span class="reserved-syntax">return</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    .</span><span class="identifier-syntax">WontFit</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"ReadFileWhichDidNotFitTable"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"Table is not large enough for the data in this file."</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"File being read has too many rows or columns to fit into table: table '"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">PrintTableName</span><span class="plain-syntax">) </span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="string-syntax">"'.^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    .</span><span class="identifier-syntax">NotTable</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"ReadFileWhichIsNotASavedTable"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"File doesn't hold table data."</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"File being read is not a previously saved table: table '"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">PrintTableName</span><span class="plain-syntax">) </span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="string-syntax">"'.^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">IssueSavedUnstableTable</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">IssueRTP</span><span class="plain-syntax">(</span><span class="string-syntax">"SavedUnstableTable"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="string-syntax">"Data in this table cannot reliably be saved."</span><span class="plain-syntax">, </span><span class="identifier-syntax">BasicInformKitRTPs</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"*** Tried to save a table to a file whose data is unstable: table '"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        (</span><span class="identifier-syntax">PrintTableName</span><span class="plain-syntax">) </span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="string-syntax">"'.^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">rtrue</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>
</pre>
<p class="commentary firstcommentary"><a id="SP26" class="paragraph-anchor"></a><b>&#167;26. Debugging.</b>Routines to print the state of a table, for debugging purposes only.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">[ </span><span class="identifier-syntax">TableColumnDebug</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> </span><span class="identifier-syntax">tc</span><span class="plain-syntax"> </span><span class="identifier-syntax">kov</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">100</span><span class="plain-syntax">) </span><span class="identifier-syntax">col</span><span class="plain-syntax">=</span><span class="identifier-syntax">TableFindCol</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">col</span><span class="plain-syntax">, </span><span class="reserved-syntax">false</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">k</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">tc</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_NUMBER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">kov</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TC_KOV</span><span class="plain-syntax">(</span><span class="identifier-syntax">tc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">k</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">&gt;1) </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">", "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">i</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">i</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"--"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">SayKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">kov</span><span class="plain-syntax">, </span><span class="identifier-syntax">v</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">say__p</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">TableRowDebug</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">col</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax"> </span><span class="identifier-syntax">v</span><span class="plain-syntax"> </span><span class="identifier-syntax">tc</span><span class="plain-syntax"> </span><span class="identifier-syntax">kov</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">k</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;1) || (</span><span class="identifier-syntax">i</span><span class="plain-syntax">&gt;</span><span class="identifier-syntax">k</span><span class="plain-syntax">)) </span><span class="string-syntax">"No such row"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"(row "</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">, </span><span class="string-syntax">")  |"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">col</span><span class="plain-syntax">=1: </span><span class="identifier-syntax">col</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;0: </span><span class="identifier-syntax">col</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">tc</span><span class="plain-syntax"> = ((</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;1) &amp; </span><span class="identifier-syntax">TB_COLUMN_NUMBER</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">kov</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TC_KOV</span><span class="plain-syntax">(</span><span class="identifier-syntax">tc</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">v</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">tab</span><span class="plain-syntax">--&gt;</span><span class="identifier-syntax">col</span><span class="plain-syntax">)--&gt;(</span><span class="identifier-syntax">i</span><span class="plain-syntax">+</span><span class="identifier-syntax">COL_HSIZE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">v</span><span class="plain-syntax"> == </span><span class="identifier-syntax">TABLE_NOVALUE</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">CheckTableEntryIsBlank</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">,</span><span class="identifier-syntax">col</span><span class="plain-syntax">,</span><span class="identifier-syntax">i</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"-- "</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">SayKindValuePair</span><span class="plain-syntax">(</span><span class="identifier-syntax">kov</span><span class="plain-syntax">, </span><span class="identifier-syntax">v</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">" |"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">say__p</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">];</span>

<span class="plain-syntax">[ </span><span class="identifier-syntax">TableDebug</span><span class="plain-syntax"> </span><span class="identifier-syntax">tab</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> </span><span class="identifier-syntax">k</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">PrintTableName</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">); </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">k</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TableRows</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">=1:</span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;=</span><span class="identifier-syntax">k</span><span class="plain-syntax">:</span><span class="identifier-syntax">i</span><span class="plain-syntax">++) { </span><span class="identifier-syntax">TableRowDebug</span><span class="plain-syntax">(</span><span class="identifier-syntax">tab</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">); </span><span class="reserved-syntax">print</span><span class="plain-syntax"> </span><span class="string-syntax">"^"</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">];</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="srt.html">&#10094;</a></li><li class="progresssection"><a href="dfntn.html">dfntn</a></li><li class="progresssection"><a href="strtp.html">strtp</a></li><li class="progresssection"><a href="utlts.html">utlts</a></li><li class="progresssection"><a href="prgrp.html">prgrp</a></li><li class="progresssection"><a href="mthmt.html">mthmt</a></li><li class="progresssection"><a href="srt.html">srt</a></li><li class="progresscurrent">tbls</li><li class="progresssection"><a href="mstck.html">mstck</a></li><li class="progresssection"><a href="rlbks.html">rlbks</a></li><li class="progresssection"><a href="actvt.html">actvt</a></li><li class="progresssection"><a href="prntn.html">prntn</a></li><li class="progresssection"><a href="flx.html">flx</a></li><li class="progresssection"><a href="blckv.html">blckv</a></li><li class="progresssection"><a href="knds.html">knds</a></li><li class="progresssection"><a href="txt.html">txt</a></li><li class="progresssection"><a href="chr.html">chr</a></li><li class="progresssection"><a href="rgxp.html">rgxp</a></li><li class="progresssection"><a href="lsts.html">lsts</a></li><li class="progresssection"><a href="cmbnt.html">cmbnt</a></li><li class="progresssection"><a href="rltnk.html">rltnk</a></li><li class="progresssection"><a href="rltns.html">rltns</a></li><li class="progresssection"><a href="prprt.html">prprt</a></li><li class="progresssection"><a href="rtp.html">rtp</a></li><li class="progressnext"><a href="mstck.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

